/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q2515.java
 * @Author : WangRuoyu
 * @Date 2023/1/11 11:06
 */

package leetcode;

public class Q2515 {
    public int closetTarget(String[] words, String target, int startIndex) {
        int res = 200;


        for (int i = 0; i < words.length; i++) {
            if (words[i].equals(target)) {
                int diff = Math.max(i, startIndex) - Math.min(i, startIndex);
                res = Math.min(res, diff);
                res = Math.min(res, words.length - diff);
            }
        }

        if (res == 200) {
            return -1;
        }

        return res;
    }

    public static void main(String[] args) {
        Q2515 sl = new Q2515();
        String[] words = {"hello", "i", "am", "leetcode", "hello"};
        String target = "hello";
        int startIndex = 1;
        System.out.println(sl.closetTarget(words, target, startIndex));
    }
}
